
SET R0 6	#m
SET R1 4	#n


SET R2 1 	#callback
COPY R3 R0	#m!

BRANCH factorial
:first
PUSH R4


SET R2 2	#Callback
COPY R3 R1	#n!
BRANCH factorial
:second
PUSH R4


SET R2 3	#Callback
SUB R3 R0 R1	#M-N

BRANCH factorial
:third


COPY R1 R4	#(M-N)!
POP R2		#N!
POP R3		#M!


MUL R1 R1 R2
DIV R0 R3 R1

PUSH R0        #push value to print
SET R4 1
PUSH R4        #push console ID 
TRAP           #print to console

BRANCH endProg

:factorial
#R2 Callback
#R3 Input

PUSH R0 
PUSH R1
PUSH R3
SET R4 1 #result

SET R1 -1       #increment amount
SET R0 2 		#limit 

BLT R3 R0 end
SET R0 1
:loop
MUL R4 R4 R3
ADD R3 R1 R3   #increment R1
BNE R0 R3 loop #repeat until R0=R3
:end

SET R0 1
SET R1 2
SET R3 3


BNE R2 R0 CONT1# FIRST
POP R3
POP R1
POP R0
BRANCH first
:CONT1
BNE R2 R1 CONT2# SECOND
POP R3
POP R1
POP R0
BRANCH second
:CONT2
POP R3
POP R1
POP R0
BRANCH third



:endProg



